Imports System
Imports System.Text
Imports System.Configuration
Imports System.Collections.Generic
Imports Microsoft.Practices.EnterpriseLibrary.Configuration.Design

''' <summary>
''' Represents the design manager for the $Caption$ settings configuration section.
''' </summary>
Public NotInheritable Class ConfigurationDesignManager
	Inherits Microsoft.Practices.EnterpriseLibrary.Configuration.Design.ConfigurationDesignManager

	''' <summary>
	''' Initializes a new instance of the <see cref="ConfigurationDesignManager"/> class.
	''' </summary>
	Public Sub New()

	End Sub

	''' <summary>
	''' Register the commands and node maps needed for the design manager into the design time.
	''' </summary>
	''' <param name="serviceProvider">The a mechanism for retrieving a service object that is, an object that provides custom support to other objects.</param>
	Public Overrides Sub Register(ByVal serviceProvider As IServiceProvider)
		Dim cmdRegistrar As CommandRegistrar = New CommandRegistrar(serviceProvider)
		cmdRegistrar.Register()
		Dim nodeRegistrar As NodeMapRegistrar = New NodeMapRegistrar(serviceProvider)
		nodeRegistrar.Register()
	End Sub

	''' <summary>
	''' Gets the a <see cref="ConfigurationSectionInfo"/> for the security settings configuration section.
	''' </summary>
	''' <param name="serviceProvider">The a mechanism for retrieving a service object that is, an object that provides custom support to other objects.</param>
	''' <returns>A <see cref="ConfigurationSectionInfo"/> for the security settings configuration section.</returns>
	Protected Overrides Function GetConfigurationSectionInfo(ByVal serviceProvider As IServiceProvider) As ConfigurationSectionInfo
		Dim rootNode As ConfigurationNode = ServiceHelper.GetCurrentRootNode(serviceProvider)
		Dim node As ApplicationBlockSettingsNode = Nothing
		If Not rootNode Is Nothing Then
			node = CType(rootNode.Hierarchy.FindNodeByType(rootNode, GetType(ApplicationBlockSettingsNode)), ApplicationBlockSettingsNode)
		End If
		Dim blockSettings As ApplicationBlockSettings = Nothing
		If Not node Is Nothing Then
			Dim builder As ApplicationBlockSettingsBuilder = New ApplicationBlockSettingsBuilder(serviceProvider, node)
			blockSettings = builder.Build()
		End If
		Return New ConfigurationSectionInfo(node, blockSettings, ApplicationBlockSettings.SectionName)
	End Function

	''' <summary>
	''' Initializes the $Caption$.
	''' </summary>
	''' <param name="serviceProvider">The a mechanism for retrieving a service object that is, an object that provides custom support to other objects.</param>
	''' <param name="rootNode">The root node of the application.</param>
    ''' <param name="section">The <see cref="ConfigurationSection"/> that was opened from the <see cref="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.IConfigurationSource"/>.</param>
	Protected Overrides Sub OpenCore(ByVal serviceProvider As IServiceProvider, ByVal rootNode As ConfigurationApplicationNode, ByVal section As System.Configuration.ConfigurationSection)
		If Not section Is Nothing Then
			Dim builder As ApplicationBlockSettingsNodeBuilder = New ApplicationBlockSettingsNodeBuilder(serviceProvider, CType(section, ApplicationBlockSettings))
			rootNode.AddNode(builder.Build())
		End If
	End Sub
End Class
